home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / ghostscript / 8.64 / Resource / Init / gs_dps.ps < prev    next >
Encoding:
Text File  |  2009-04-17  |  7.8 KB  |  225 lines

  1. %    Copyright (C) 1997, 2000 Aladdin Enterprises.  All rights reserved.
  2. % This software is provided AS-IS with no warranty, either express or
  3. % implied.
  4. % This software is distributed under license and may not be copied,
  5. % modified or distributed except as expressly authorized under the terms
  6. % of the license contained in the file LICENSE in this distribution.
  7. % For more information about licensing, please refer to
  8. % http://www.ghostscript.com/licensing/. For information on
  9. % commercial licensing, go to http://www.artifex.com/licensing/ or
  10. % contact Artifex Software, Inc., 101 Lucas Valley Road #110,
  11. % San Rafael, CA  94903, U.S.A., +1(415)492-9861.
  12.  
  13. % $Id: gs_dps.ps 8954 2008-08-08 04:22:38Z ray $
  14. % Initialization file for Display PostScript functions.
  15.  
  16. % ------ Errors ------ %
  17.  
  18. % These errors are only defined in DPS.
  19. { /invalidcontext /invalidid } { .registererror } forall
  20.  
  21. % ------ Contexts ------ %
  22.  
  23. % To create a context with private local VM, we use the .localfork
  24. % operator to actually create the context, the new VM, and an empty
  25. % userdict, and then we call the .initlocaldicts procedure to make
  26. % local copies of the initial contents of the dictionaries in local VM.
  27. % savedlocaldicts in systemdict is a global read-only dictionary whose
  28. % elements are global read-only copies of these initial contents;
  29. % we just copy its elements into local VM and install them in systemdict.
  30. % userdict and internaldict require special handling.
  31.  
  32. % Switching between contexts with different local VMs requires
  33. % changing the bindings in systemdict that reference local objects.
  34. % For this purpose, each userdict has an entry called localdicts
  35. % which holds the local copies of the elements of savedlocaldicts,
  36. % plus internaldict.  The context switching code in the interpreter
  37. % effectively copies this dictionary into systemdict.
  38. % NOTE: the name localdicts is known to the interpreter.
  39.  
  40. % Switching between contexts also requires resetting the user parameters.
  41. % The interpreter records the value of userparams (a local dictionary
  42. % referenced from systemdict) for each context, and uses it for this.
  43. % See gs_lev2.ps for more details.
  44. % NOTE: the name userparams is known to the interpreter.
  45.  
  46. % Save copies of local dictionaries at the end of system initialization.
  47. % Also save the initial gstate.
  48. /.savelocalstate {
  49.   .currentglobal true .setglobal
  50.   //systemdict /savedlocaldicts mark //systemdict {
  51.     dup gcheck {
  52.       pop pop
  53.     } {
  54.       dup type /dicttype eq {
  55.         % Save a copy of this dictionary in global VM.
  56.     dup maxlength dict .copydict readonly
  57.       } {
  58.     pop pop
  59.       } ifelse
  60.     } ifelse
  61.   } forall .dicttomark readonly put
  62.         % Create localdicts for the current context.
  63.   false .setglobal
  64.   userdict /localdicts mark savedlocaldicts {
  65.     pop dup load
  66.   } forall /internaldict dup load
  67.   .dicttomark readonly put
  68.         % Save a copy of the initial gstate.
  69.   true .setglobal
  70.   //systemdict /savedinitialgstate gstate readonly put
  71.   .setglobal
  72. } .bind def
  73.  
  74. % Initialize local dictionaries and gstate when creating a new context.
  75. % Note that until this completes, we are in the anomalous situation of
  76. % having systemdict point to dictionaries that are in a non-current
  77. % local VM.  Because of this, we turn off garbage collection temporarily.
  78. /.copylocal {        % <name> <dict> .copylocal <name> <dict'>
  79.         % Copy a dictionary to the current (local) VM,
  80.         % and make it read-only if its current definition is.
  81.   dup maxlength dict .copydict
  82.   1 index load wcheck not { readonly } if
  83. } .bind def
  84. % When this is called, the dictionary stack is in its initial state,
  85. % and there is (anomalously) only one gstate on the gstate stack.
  86. /.initlocaldicts {        % - .initlocaldicts -
  87.   -2 vmreclaim
  88.   .currentglobal //systemdict begin
  89.   false .setglobal
  90.         % Since localdicts doesn't exist yet, references from
  91.         % systemdict to local objects won't get restored if
  92.         % a context switch happens in this code.  Therefore,
  93.         % until localdicts is defined, we have to keep all our
  94.         % state on the operand stack.
  95.  
  96.         % Acquire userdict.
  97.         %****** WRONG IF NON-STANDARD INITIAL DSTACK ******
  98.   countdictstack array dictstack
  99.    { dup gcheck not { exit } if pop } forall
  100.         % Create localdicts with a local copy of each dictionary,
  101.         % except for userdict and userparams, which just need
  102.         % to be filled in.
  103.   mark savedlocaldicts {
  104.     1 index /userdict eq {
  105.         % Stack: userdict mark ... /userdict inituserdict
  106.       counttomark 1 add index .copydict
  107.     } {
  108.       1 index /userparams eq {
  109.         % Stack: userdict mark ... /userparams inituserparams
  110.     userparams .copydict
  111.       } {
  112.     .copylocal
  113.       } ifelse
  114.     } ifelse
  115.   } forall /internaldict dup .makeinternaldict .makeoperator
  116.   .dicttomark readonly /localdicts exch put
  117.         % localdicts is now defined in userdict.
  118.         % Copy the definitions into systemdict.
  119.   localdicts { .forcedef } forall
  120.         % Set the user parameters.
  121.   userparams readonly .setuserparams
  122.         % Establish the initial gstate(s).
  123.   /savedinitialgstate .systemvar setgstate gsave
  124.         % Wrap up.
  125.   end .setglobal
  126. } odef
  127.  
  128. % Check whether an object is a procedure.
  129. /.proccheck {            % <obj> .proccheck <bool>
  130.   dup xcheck
  131.   exch type dup /arraytype eq exch /packedarraytype eq or and
  132. } bind def
  133.  
  134. % Create a context with private local VM.
  135. % The .localfork operator does all the work, but we must ensure that
  136. % .initlocaldicts gets called when the new context starts up.
  137. /localfork {            % <mark> <obj1> ... <objN> <proc>
  138.                 %   <stdin|null> <stdout|null>
  139.                 %   localfork <context>
  140.   .currentglobal true .setglobal 3 index
  141.   dup .proccheck not {
  142.     pop .setglobal /localfork .systemvar /typecheck signalerror
  143.   } if
  144.   {exec .initlocaldicts} aload pop
  145.   3 1 roll 3 packedarray cvx
  146.   4 1 roll 5 -1 roll pop .setglobal .localfork
  147. } odef
  148.  
  149. % Fork a context that shares VM.  The .fork operator creates an empty
  150. % userparams dictionary for the context, but we still need to initialize
  151. % this dictionary when the new context starts up.
  152. /.postfork {        % - .postfork -
  153.     % Initialize the user parameters.
  154.   savedlocaldicts /userparams get userparams .copydict readonly pop
  155. } odef
  156. /fork {            % <mark> <obj1> ... <objN> <proc> fork <context>
  157.   .currentglobal false .setglobal 1 index
  158.   dup .proccheck not {
  159.     pop .setglobal /fork .systemvar /typecheck signalerror
  160.   } if
  161.   {exec .postfork} aload pop
  162.   3 1 roll 3 packedarray cvx
  163.   3 1 roll exch pop .setglobal .fork
  164. } odef
  165.  
  166. % ------ Halftone phase ------ %
  167.  
  168. /sethalftonephase {        % <x> <y> sethalftonephase -
  169.   -1 2 index 2 index .setscreenphase pop pop
  170. } odef
  171. /currenthalftonephase {        % - currenthalftonephase <x> <y>
  172.   0 .currentscreenphase
  173. } odef
  174.  
  175. % ------ Device-source images ------ */
  176.  
  177. .imagetypes 2 /.image2 load put
  178.  
  179. % ------ Device information ------ %
  180.  
  181. /.deviceinfodict mark
  182.   /Colors null /GrayValues null /RedValues null /GreenValues null
  183.   /BlueValues null /ColorValues null
  184. .dicttomark readonly def
  185. /deviceinfo {            % - deviceinfo <dict>
  186.   currentdevice //.deviceinfodict .getdeviceparams .dicttomark
  187.   dup begin
  188.   /ColorValues .knownget {
  189.     0 le
  190.     { currentdict /ColorValues undef }
  191.     {
  192.       % hack around devices that incorrect set GrayValues
  193.       Colors 3 eq { 1 } { GrayValues } ifelse
  194.       RedValues mul GreenValues mul BlueValues mul ColorValues ne
  195.       { currentdict /GrayValues undef
  196.         currentdict /RedValues undef
  197.         currentdict /GreenValues undef
  198.         currentdict /BlueValues undef
  199.       } if
  200.     }
  201.     ifelse
  202.   } if
  203.   currentdict end readonly
  204. } odef
  205.  
  206. % The current implementation allocates a 2-element array each time.
  207. % Perhaps we should change this to 2 separate parameters for X and Y?
  208. /.wtdict mark
  209.   /wtranslation null
  210. .dicttomark readonly def
  211. /wtranslation {            % - wtranslation <x> <y>
  212.   currentdevice //.wtdict .getdeviceparams exch pop exch pop aload pop
  213. } odef
  214. currentdict /.wtdict .undef
  215.  
  216. % ------ View clipping ------ %
  217.  
  218. /rectviewclip {            % <x> <y> <width> <height> rectviewclip -
  219.                 % <numarray|numstring> rectviewclip -
  220.   newpath .rectappend viewclip
  221. } odef
  222.